package com.mike.server.system.role;

import org.apache.log4j.Logger;

import com.mike.game.protocols.RoleSystenProtocols;
import com.mike.server.engine.BaseGameMessage;
import com.mike.server.engine.IGameMessage;
import com.mike.server.support.BaseService;
import com.mike.server.system.role.messages.CreateRoleMessage;
import com.mike.server.system.role.messages.DeleteRoleMessage;
import com.mike.server.system.role.messages.UpdateRoleMessage;

public class RoleService extends BaseService {

	private static final Logger LOG = Logger.getLogger(RoleService.class);
	
	private static RoleService instance = new RoleService();
	
	private RoleService() {
		//Don't allow new it outside.
	}
	
	public static RoleService getInstance() {
		return instance;
	}

	@Override
	public void onReceive(IGameMessage gameMessage) {
		if(null == gameMessage){
			LOG.error("onReceive: GameMessage is null.");
			return;
		}
		
		if(IGameMessage.ROLE_SYSTEM != gameMessage.getType()) {
			LOG.error("onReceive: GameMessage Type:" + gameMessage.getType() + " this system type:" + IGameMessage.ROLE_SYSTEM);
		}
		
		BaseGameMessage baseGameMessages = null;
		switch (gameMessage.getId()) {
			case RoleSystenProtocols.CREATE_ROLE:
				baseGameMessages = new CreateRoleMessage(gameMessage);
				break;
			case RoleSystenProtocols.UPDATE_ROLE:
				baseGameMessages = new UpdateRoleMessage(gameMessage);
				break;
			case RoleSystenProtocols.DELETE_ROLE:
				baseGameMessages = new DeleteRoleMessage(gameMessage);
				break;
		}
		if(null != baseGameMessages) {
			baseGameMessages.run();
		}
		baseGameMessages = null;
	}
	
}
